package org.budo.activiti.expression;

import org.activiti.engine.delegate.Expression;
import org.activiti.engine.delegate.VariableScope;
import org.budo.support.spring.util.SpringUtil;

/**
 * @author lmw
 * @see org.activiti.engine.impl.el.JuelExpression
 */
public class BudoActivitiExpressionWrapper implements Expression {
    private static final long serialVersionUID = 4143743727759297390L;

    private Expression expression;

    public BudoActivitiExpressionWrapper(Expression expression) {
        this.expression = expression;
    }

    @Override
    public Object getValue(VariableScope variableScope) {
        BudoActivitiExpressionDelegate expressionDelegate = SpringUtil.getBean(BudoActivitiExpressionDelegate.class);
        if (null != expressionDelegate) {
            return expressionDelegate.getValue(this.expression, variableScope);
        }

        return this.expression.getValue(variableScope);
    }

    @Override
    public void setValue(Object value, VariableScope variableScope) {
        this.expression.setValue(value, variableScope);
    }

    @Override
    public String getExpressionText() {
        return this.expression.getExpressionText();
    }
}